package com.itheima.tanhua.vo;

import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSON;
import com.itheima.tanhua.domain.Personality;
import com.itheima.tanhua.domain.Score;
import com.itheima.tanhua.domain.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Lff
 * @date 2022/4/9
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PersonalityVo implements Serializable {
    private String conclusion;
    private String cover;
    private DimensionsVo[] dimensions;
    private SimilarYouVo[] similarYou;

    //根据UserInfo动态生成

    public static PersonalityVo init(Personality personality, List<UserInfo> users, Score score) {
        // 虚拟维度数据
        /*DemensisonsVo demensisons = new DemensisonsVo("判断", "90%");
        DemensisonsVo demensisons1 = new DemensisonsVo("抽象", "70%");
        DemensisonsVo demensisons2 = new DemensisonsVo("外向", "80%");
        DemensisonsVo demensisons3 = new DemensisonsVo("理性", "80%");*/
        String demensisons = score.getDimensions();
        DimensionsVo[] dimensionsVos = JSON.parseObject(demensisons, DimensionsVo[].class);
        PersonalityVo vo = new PersonalityVo();
        //填充维度数据
        vo.setDimensions(dimensionsVos);
        //填充封面
        vo.setCover(personality.getCoverImg());
        //填充内容
        vo.setConclusion(personality.getContent());
        //填充推荐用户
        List<SimilarYouVo> list = new ArrayList<>();
        for (UserInfo user : users) {
            if (user != null) {
                list.add(new SimilarYouVo(user.getId(), user.getAvatar()));
            }
        }
        SimilarYouVo[] similarYous = ArrayUtil.toArray(list, SimilarYouVo.class);
        //推荐用户
        vo.setSimilarYou(similarYous);
        return vo;
    }
}

